package com.huike.review.service.impl;

import com.huike.common.core.domain.AjaxResult;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.bean.BeanUtils;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.mapper.MybatisReviewMapper;
import com.huike.review.vo.MybatisReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


/**
 * mybatis复习使用的业务层
 * 注意该业务层和我们系统的业务无关，主要是让同学们快速熟悉系统的
 */
@Service
@Transactional
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private MybatisReviewMapper reviewMapper;


    @Override
    public Review findById(Long id) {
        return reviewMapper.findById(id);
    }



    //添加信息
    @Override
    public void save(String name, Integer age, String sex) {

        //填充数据
        Review review = new Review();
        review.setCreateBy("李晟");
        review.setCreateTime(new Date());
        review.setUpdateBy("李晟");
        review.setUpdateTime(new Date());
        review.setName(name);
        review.setAge(age);
        review.setSex(sex);

        //添加信息
        reviewMapper.save(review);
    }

    //修改信息
    @Override
    public void update(Review review) {
        review.setUpdateTime(new Date());
        review.setUpdateBy("李某人");
        reviewMapper.update(review);
    }

    //删除信息
    @Override
    public void delete(Integer id) {
        reviewMapper.delete(id);
    }

    //分页
    @Override
    public List<Review> list() {
       List<Review>reviews= reviewMapper.findAll();
        return reviews;
    }
}
